import datetime, time, json

from decimal import Decimal


# 处理decimal（python  不识别） 转成 float
def convert_decimal_to_float(ob):
    if isinstance(ob, Decimal):
        return float(ob)
    if isinstance(ob, (tuple, list)):
        return [convert_decimal_to_float(v) for v in ob]
    if isinstance(ob, dict):
        return {k: convert_decimal_to_float(v) for k, v in ob.items()}
    return ob


def get_consumer_now__format(format=None):
    """
    format 自定义格式
    默认返回当前时间
    """
    now = datetime.datetime.now()
    if format:
        return now.__format__(format)
    return now


# 对比时间获取时间差（秒）
def contrast_str_time(before_time, after_time):
    if isinstance(before_time, str):
        before_time = time.strptime(before_time, "%Y-%m-%d %H:%M:%S")
    if isinstance(after_time, str):
        after_time = time.strptime(after_time, "%Y-%m-%d %H:%M:%S")
    return int(time.mktime(after_time)) - int(time.mktime(before_time))


# 获取时间差 微秒
def get_contrast_time(after_time):
    return contrast_str_time(get_consumer_now__format('%Y-%m-%d %H:%M:%S'), after_time) * 1000


if __name__ == '__main__':
    a = '88739'
    num = 0

    strLine = ''
    w = open('d://1.txt', 'w', encoding='utf-8')
    with open('d://26.sql', 'r', encoding='utf-8', errors='ignore') as foo:
        for line in foo.readlines():
            num += line.count('\n')
            if a in line:
                w.write(line)
                w.write(str(num))
                w.write('\n')

    w.close()
